package leetcode.每日一题;

import java.util.Arrays;

/**
 * @author ：zsy
 * @date ：Created 2021/7/14 20:49
 * @description：
 */
public class SelectSort {

    public static void main(String[] args) {
        selectSort(new int[]{9, 7, 8, 4, 5, 2});
    }

    public static void selectSort(int[]arr) {
        int len = arr.length;
        for (int i = 0; i < len - 1; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < len; j++) {
                if (arr[j] < min) {
                    minIndex = j;
                    min = arr[j];
                }
            }
            if (minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
